package com.wave.wavesystem.business.interceptor;

import com.wave.wavesystem.common.constant.RequestConstant;
import com.wave.wavesystem.common.util.Func;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 夕下风波
 * @date 2025-02-01 18:16
 * @description
 */
@Slf4j
public class RequestHeaderInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String header = request.getHeader(RequestConstant.WITH_REQUEST_K);
        if (Func.isEmpty(header)) return false;
        return header.equals(RequestConstant.WITH_REQUEST_V);

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        log.error("非法请求！未携带指定请求头");
    }

}
